<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@taglib prefix="sec"
	uri="http://www.springframework.org/security/tags"%>


<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<base href="<%=basePath%>" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>${applicationScope.KEY_SITE_NAME}</title>
<link href="resources/css/jquery-ui.css" rel="stylesheet"
	type="text/css" />
<link href="resources/css/ichecker/square/blue.css" rel="stylesheet"
	type="text/css" />
<link href="resources/css/intstyle.css" rel="stylesheet" type="text/css" />

<script type="text/javascript" src="resources/scripts/jquery-1.9.1.js"></script>
<script type="text/javascript"
	src="resources/scripts/jquery-ui.custom.js"></script>
<script type="text/javascript" src="resources/scripts/jquery.blockUI.js"></script>
<script type="text/javascript" src="resources/scripts/jquery.icheck.js"></script>
<script type="text/javascript" src="resources/scripts/common.js"></script>
<script type="text/javascript"
	src="resources/scripts/jquery.validate.js"></script>

<script type="text/javascript">
	$(document)
			.ready(
					function() {

						renderButtons();
						changeSideMenuBackColor("sideMenuIntUsrAdd");
						renderCheckBox();

						$("#form1")
								.validate(
										{
											rules : {												
												userM : {
													required : true,
													maxlength : 40,
													minlength : 2
												},
												qq : {
													maxlength : 60
												},
												email : {
													email : true,
													maxlength : 60
												}

											},
											messages : {												
												userM : {
													required : "<spring:message code='msg.input.field.required'/>",
													maxlength : jQuery
															.format("<spring:message code='msg.input.field.maxlength'/>"),
													minlength : jQuery
															.format("<spring:message code='msg.input.field.minlength'/>")
												},
												qq : {
													maxlength : jQuery
															.format("<spring:message code='msg.input.field.maxlength'/>")
												},
												email : {
													email : "<spring:message code='msg.input.email.format'/>",
													maxlength : jQuery
															.format("<spring:message code='msg.input.field.maxlength'/>")
												}
											},

											submitHandler : function(form) {
												saveAdminUser(
														"admin/user/internal/update",
														"form1");
											}

										});

						$("#form2")
								.validate(
										{
											rules : {
												orgpassword : {
													required : true,
													remote : {
														url : 'admin/user/checkpassword',
														type : 'POST',
														dateType : 'json',
														data : {
												        	  
												        	   password:function(){
												            	   return $('#orgpassword').val();
												               },
												        	   userId:function(){
												               	 return $('#userId').val();
												               }
												               
												          }
													}
												},
												password : {
													required : true,
													minlength : 5,
													maxlength : 30
												},
												re_passwrod : {
													required : true,
													minlength : 5,
													maxlength : 30,
													equalTo : "#password"
												}
											},
											messages : {
												orgpassword : {
													required : "<spring:message code='msg.input.field.required'/>",
													remote : "<spring:message code='msg.setpwd.org.wrong'/>"
												},
												password : {
													required : "<spring:message code='msg.input.field.required'/>",
													maxlength : jQuery
															.format("<spring:message code='msg.input.field.maxlength'/>"),
													minlength : jQuery
															.format("<spring:message code='msg.input.field.minlength'/>")
												},
												re_passwrod : {
													required : "<spring:message code='msg.input.field.required'/>",
													maxlength : jQuery
															.format("<spring:message code='msg.input.field.maxlength'/>"),
													minlength : jQuery
															.format("<spring:message code='msg.input.field.minlength'/>"),
													equalTo : "<spring:message code='msg.input.password.notEqual'/>"
												}
											},

											submitHandler : function(form) {
												saveAdminUser(
														"admin/user/internal/pws/update",
														"form2");
											}

										});

					});

	function saveAdminUser(action, formId) {

		getBlockUI();
		$.post(action, $("#" + formId).serialize(), function(obj, html) {
			$.unblockUI();
			if (obj.accessDenied) {
				showInfoDialog("error", data.message);
			} else {
				showInfoDialog("success",
						"<spring:message code='msg.dialog.save.ok'/>", function(){
							window.location.href = "admin/user/internal/list";
				});
				
			}
		});
	}
//-->
</script>

<!--[if lte IE 7]>
<style>
.content { margin-right: -1px; } /* 此 1px 负边距可以放置在此布局中的任何列中，且具有相同的校正效果。 */
ul.nav a { zoom: 1; }  /* 缩放属性将为 IE 提供其需要的 hasLayout 触发器，用于校正链接之间的额外空白 */
</style>
<![endif]-->
</head>

<body>

	<div class="container"><%@include file="../header.jsp"%>
		<%@include file="sidebar.jsp"%>
		<div id="contentBoxDiv" class="content">
			<div class="subnav">
				<spring:message code="Label.menu.headnav.user" />
				&gt;&gt;
				<spring:message code="Label.menu.sidenav.user.title.int" />
				&gt;&gt;
				<spring:message code="Label.menu.sidenav.user.int.add" />
				&gt;&gt;
				<spring:message code="Label.menu.sidenav.user.int.edit" />
			</div>
			<%@include file="../errorMessagePanel.jsp"%>
			<c:if test="${not empty user}">

				<div class="box">
					<h2>
						<spring:message code="Label.user.internal.info.edit" />
					</h2>
					<br/>
					<div class="box" style="border: none;">
						<div class="titlebox">
							<div class="boxtitle">
								<label><spring:message code="Label.user.internal.info" /></label>
							</div>
							<form id="form1" name="form1" method="post" action="">

								<fieldset>
									<div class="formfield">

										<div class="formLabel">
											<label for="userId"><spring:message
													code="Label.adminuser.id" /></label>
										</div>
										<div class="forminput">
											<input type="text" id="userId" name="userId"
												class="text ui-widget-content ui-corner-all"
												value="${user.userId}" readonly="readonly" />
										</div>

									</div>

									<div class="formfield">

										<div class="formLabel">
											<label for="userM"><spring:message
													code="Label.adminuser.name" /></label>
										</div>
										<div class="forminput">
											<input type="text" id="userM" name="userM"
												class="text ui-widget-content ui-corner-all"
												value="${user.userM}" />
										</div>

									</div>

									<div class="formfield">

										<div class="formLabel">
											<label for="qq"><spring:message
													code="Label.user.buyer.qq" /></label>
										</div>
										<div class="forminput">
											<input type="text" id="qq" name="qq"
												class="text ui-widget-content ui-corner-all"
												value="${user.qq}" />
										</div>

									</div>

									<div class="formfield">

										<div class="formLabel">
											<label for="email"><spring:message
													code="Label.user.buyer.email" /></label>
										</div>
										<div class="forminput">
											<input type="text" id="email" name="email"
												class="text ui-widget-content ui-corner-all"
												value="${user.email}" />
										</div>

									</div>

									<div class="formfield">

										<div class="formLabel">
											<label for="role"><spring:message
													code="Label.user.role" /></label>
										</div>

										<div class="forminput">
											<div class="button-group-div" style="width: 50%">
												<c:if test="${not empty roleList}">
													<c:forEach items="${roleList}" var="role">
														<div id="authListCol"
															style="width: 150px; margin-bottom: 12px;">

															<div>
																<input type="checkbox" name="selectedRoleList"
																	id="check${role.roleId}" value="${role.roleId}"
																	<c:forEach items="${user.roleList}" var="userrole">
																	<c:if test="${userrole.roleId eq role.roleId}">
																	checked="checked"
																	</c:if>																
																</c:forEach> />
															</div>

															<div>
																<label for="check${role.roleId}"
																	id="label${role.roleId}"><spring:message
																		code="${role.roleName}" /></label>
															</div>
														</div>
													</c:forEach>
												</c:if>
											</div>
										</div>
										<div class="clearfloat"></div>

									</div>

									<div class="forminput">
										<button type="submit" id="submitbtn">
											<spring:message code='Label.common.save' />
										</button>
										<button type="reset" id="reset">
											<spring:message code='Label.common.reset' />
										</button>
									</div>

								</fieldset>
							</form>
						</div>

						<br/>
						<br/>
						<div class="titlebox">
							<div class="boxtitle">
								<label><spring:message
										code="Label.common.change.password" /></label>
							</div>
							<form id="form2" name="form2" method="post" action="">

								<fieldset>

									<div class="formfield">

										<div class="formLabel">
											<label for="userId"><spring:message
													code="Label.adminuser.id" /></label>
										</div>
										<div class="forminput">
											<input type="text" id="userId" name="userId"
												class="text ui-widget-content ui-corner-all"
												value="${user.userId}" readonly="readonly" />
										</div>

									</div>

									<div class="formfield">

										<div class="formLabel">
											<label for="orgpassword"><spring:message
													code="Label.adminuser.edit.orgpassword" /></label>
										</div>
										<div class="forminput">
											<input type="password" id="orgpassword" name="orgpassword"
												class="text ui-widget-content ui-corner-all" />
										</div>

									</div>

									<div class="formfield">

										<div class="formLabel">
											<label for="password"><spring:message
													code="Label.adminuser.password" /></label>
										</div>
										<div class="forminput">
											<input type="password" id="password" name="password"
												class="text ui-widget-content ui-corner-all" />
										</div>

									</div>

									<div class="formfield">

										<div class="formLabel">
											<label for="re_passwrod"><spring:message
													code="Label.adminuser.repassword" /></label>
										</div>
										<div class="forminput">
											<input type="password" id="re_passwrod" name="re_passwrod"
												class="text ui-widget-content ui-corner-all" />
										</div>

									</div>

									<div class="forminput">
										<button type="submit" id="submitbtn2">
											<spring:message code='Label.common.save' />
										</button>
										<button type="reset" id="reset2">
											<spring:message code='Label.common.reset' />
										</button>
									</div>

								</fieldset>
							</form>
						</div>
					</div>
				</div>
			</c:if>
			<!-- end .content -->
		</div>
		<div class="clearfloat" />
		<%@include file="../footer.jsp"%>
		<!-- end .container -->
	</div>
</body>
</html>